package demo12;

import demo11.Tree;

import java.util.List;
import java.util.Scanner;

public class Tree2Main {

        public static void main(String[] args) {
            Tree tree1 = new Tree();
            Tree.TreeNode head = tree1.creat();
            System.out.println("先序打印：");
            tree1.prevnode(head);//先序打印
            System.out.println(

            );
            System.out.println("中序打印：");
            tree1.inorder(head);//中序打印
            System.out.println();
            System.out.println("后序打印：");
            tree1.pastorder(head);
            System.out.println();
            System.out.println("====第二种先序遍历====");
            List<Character> list1 = tree1.pre(head);
            System.out.println(list1 + " ");
            System.out.println("=====第三种先序遍历===");
            List<Character> list2 = tree1.pre2(head);
            System.out.println(list2 + " ");
            System.out.println("第一种方法获取二叉树结点个数：");
            int count = tree1.size(head);
            System.out.println(count + " ");
            System.out.println("第二种方法获取二叉树结点个数：");
            int count1 = tree1.size1(head);
            System.out.println(count1 + "");
            System.out.println("获取二叉树的叶子结点个数：");
            int count3 = tree1.getLeafNode(head);
            System.out.println("叶子结点个数为：" + count3);
            System.out.println("求第k层的节点个数，请输入k：");
            Scanner in = new Scanner(System.in);
            // int k= in.nextInt();
            int k = 2;
            int num2 = tree1.getlevel(head, k);
            System.out.println("第k层结点个数为：" + num2);
            System.out.println("二叉树的高度为：");
            int h = tree1.getHeight(head);
            System.out.println("高度为：" + h);
            System.out.println("查看值是否在二叉树中：");
            Tree.TreeNode head1 = tree1.findval(head, 'B');
            System.out.println("树中找到了" + head1);
            System.out.println("判断两棵树是否相同");
            Tree t = new Tree();
            Tree.TreeNode p = t.creat();
            Tree.TreeNode q = t.creat();
            boolean a = tree1.isSame(p, q);
            System.out.println("两棵树是否相同：" + a);
            System.out.println("判断一树或其子树是否能在另一棵子树中找到：");
            Tree t1 = new Tree();
            Tree.TreeNode t2 = t1.creat();
            Tree.TreeNode t4 = new Tree.TreeNode('A');
            Tree.TreeNode t5 = new Tree.TreeNode('B');
            Tree.TreeNode t6 = new Tree.TreeNode('C');
            t4.left = t5;
            t4.right = t6;
            boolean n = tree1.isSubtree(t2, t4);
            System.out.println();
            System.out.println("第一棵树先序打印：");
            t1.prevnode(t2);
            System.out.println();
            System.out.println("第二棵树先序打印：");
            t1.prevnode(t4);
            System.out.println("能否找到：" + n);
            //翻转二叉树
            System.out.println("翻转二叉树：");
            Tree.TreeNode head4 = tree1.inverTree(head1);
            tree1.prevnode(head4);
            Tree2 tree13=new Tree2();
            Tree.TreeNode head13 = tree1.creat();
            boolean y=tree13.isSymmetric(head13);
            System.out.println();
            System.out.println("这棵二叉树是否是对称二叉树："+y);
            System.out.println("判断是否是平衡二叉树：");
            boolean y2=tree13.balance(head13);
            System.out.println(y2);
        }
    }

